package com.osdp.base.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.osdp.base.entity.SysDict;
import com.osdp.base.mapper.SysDictMapper;
import com.osdp.base.service.ISysDictService;
import com.osdp.base.util.Fields;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SysDictServiceImpl extends ServiceImpl<SysDictMapper, SysDict> implements ISysDictService {
    @Override
    public IPage<SysDict> pageList(SysDict sysDict, Page<SysDict> page) {
        return this.page(page, new QueryWrapper<SysDict>()
                .like(StringUtils.isNotBlank(sysDict.getDictCode()), Fields.SysDictQ.dictCode,sysDict.getDictCode())
                .like(StringUtils.isNotBlank(sysDict.getDictName()), Fields.SysDictQ.dictName,sysDict.getDictName())
                .eq(sysDict.getType() != null, Fields.SysDictQ.type,sysDict.getType())
        );
    }

    @Override
    public List<SysDict> queryAllList() {
        return this.list();
    }

    @Override
    public SysDict getByDictId(String id) {
        return this.getById(id);
    }

    @Override
    public boolean insertDict(SysDict entity) {
        return this.save(entity);
    }

    @Override
    public boolean updateDict(SysDict entity) {
        return this.updateById(entity);
    }

    @Override
    public boolean deleteDict(String id) {
        return this.removeById(id);
    }

    @Override
    public boolean deleteBatcah(List<String> ids) {
        return this.removeByIds(ids);
    }
}
